#include <iostream>
using namespace std;

void solve() {
    int a, b, k;
    cin >> a >> b >> k;

    int pa[k], pb[k], fa[a + 1], fb[b + 1];
    for (int i = 1; i <= a; i++)
        fa[i] = 0;
    for (int i = 1; i <= b; i++)
        fb[i] = 0;

    for (int i = 0; i < k; i++) {
        cin >> pa[i];
        fa[pa[i]]++;
    }

    for (int i = 0; i < k; i++) {
        cin >> pb[i];
        fb[pb[i]]++;
    }

    long long sum = 0;

    for (int i = 0; i < k; i++) {
        sum += k - fa[pa[i]] - fb[pb[i]] + 1;
    }

    cout << sum / 2 << endl;
}

int main() {
    int t;
    cin >> t;
    while (t-- > 0)
        solve();
    return 0;
}